
--智能施法
local last_click = 0
local function cast_spell_point(skill)
    
    --只能是点目标
    if skill.targettype~='点' then
		return false
	end
    if skill.smart_cast then
        -- 鼠标当前指向的位置
        local x, y = ac.message.mouse()
        local order = skill:get_order()
        local order_id = OrderId[order]
        ac.sync('智能施法',order,x,y)
        return true
    end
    return false
end

ac.message:event "键盘按下" (function(t, code, state)
    local hero = ac.unit.localunit()
    if hero and state==0 then
        for skl in hero:each_skill() do 
            if skl.has_ability and ac.message.keyboard[skl:get_hotkey()]==code then 
                if cast_spell_point(skl) then
                    return false
                end
            end 
        end
    end
    ac.console:notify('控制台-刷新技能显示',hero)
end)

ac.message:event "键盘弹起" (function(t, code, state)
    local hero = ac.unit.localunit()
    ac.console:notify('控制台-刷新技能显示',hero)
end)



ac.sync:event '智能施法'(function(_,player,order_id,x,y)
    local unit = player.selecting
    local skl = unit and unit.play_skills[order_id]
    if skl and skl:cast_check() then
        skl.target = ac.point(x,y)
        skl:cast(skl.target)
    end
end)



--特殊处理
ac.game:event '单位-准备释放技能'(function(_,unit,skill)
    if skill.tx_item then
        local skill = skill.parent_skill or skill
        local owner = unit.owner
        local hero = owner.hero
        if hero then
            unit:notify('商店-发起商品购买',unit,skill,hero,owner)
        end
        return false
    end
end)
